//
//  AFHTTPSessionManager+AZURLRequest.m
//  AZNetwork
//
//  Created by GorXion on 2018/4/3.
//  Copyright © 2018年 gaoX. All rights reserved.
//

#import "AFHTTPSessionManager+AZURLRequest.h"
#import "AZURLRequest.h"

@implementation AFHTTPSessionManager (AZURLRequest)

- (void)startRequest:(AZURLRequest *)request
             success:(void (^)(id response))success
             failure:(void (^)(NSError *error))failure
{
    switch (request.method) {
        case AZHTTPMethodGet:
        {
            [self GET:request.URLString parameters:request.parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                !success ?: success(responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                !failure ?: failure(error);
            }];
        }
            break;
        case AZHTTPMethodPost:
        {
            [self POST:request.URLString parameters:request.parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                !success ?: success(responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                !failure ?: failure(error);
            }];
        }
            break;
        case AZHTTPMethodUpload:
        {
            [self POST:request.URLString parameters:request.parameters constructingBodyWithBlock:request.constructingBodyWithBlock progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                !success ?: success(responseObject);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                !failure ?: failure(error);
            }];
        }
            break;
    }
}

@end
